<?php
/**
* @package controller
* @file indexController.php
* @date 15.09.2009
* @version 1.0
* @copyright sample
* @author Harinath Reddy
* @todo phpDoc comments
*/
require_once 'Zend/Controller/Action.php';

class tasks_IndexController extends Cms_Controller_Action
{
	public function init()
	{
		if($_SESSION["sess_userid"]=="")
		{
		$this->_redirect('/home/');
		}
	  $this->view->siteTitle = 'Tasks';
	  $this->currentPage = 1;
	  $this->resultsPerPage = 12;
	  
	  $this->view->date_fromat = $this->CONFIG->date_format->date_time;
			
	}
	
	public function indexAction()
	{
	  	
			
	}
	public function taskListAction()
	{
		$type= $this->_getParam('id');
		$memid = $_SESSION["sess_userid"];
		if($_SESSION["sess_userid"]!="")
		{
			$due_dates = Doctrine::getTable('Tasks')->getAllDueDates();
			//echo '<pre>';print_r($due_dates);exit;
			$current_date=date('Y-m-d H:i:s');
			//echo strtotime($current_date).">".strtotime($due_dates[0]['due_date']);exit;
			$count=0;
			foreach($due_dates as $due_dates)
			{
				if(strtotime($current_date)>strtotime($due_dates['due_date']))
				{
					//echo strtotime($current_date).">".strtotime($due_dates['due_date']);exit;
					$result = Doctrine::getTable('TaskRelations')->updateTaskStatusToOverDue($due_dates);
					$count++;
				}
			}
			//echo $count;exit;
			if($type==1)
			{
				$this->view->personalactive="active";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getPersonalTasks($memid,1,12);
				//echo '<pre>';print_r($result);exit;
			}
			else if($type==2)
			{
				$this->view->personalactive="";
				$this->view->assigntoactive="active";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getAssignToTasks($memid,1,12);
				//echo '<pre>';print_r($result);exit;
			}else{
				$this->view->personalactive="";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="active";
				$result = Doctrine::getTable('Tasks')->getAssignByTasks($memid,1,12);
			}
			//echo '<pre>';print_r($result);exit;
			$this->view->params ='';
			$this->view->getTasks = $result;
			$this->view->type= $type;
		}
		else
		{
			$this->_redirect("/home/");
		}
		
	}
	public function taskViewListAction()
	{
		
	}
	public function paginationAction()
	{
		$type=$this->_getParam('id');
		//echo $type;exit;
		$memid=$_SESSION["sess_userid"];
		$this->view->params ="";
		$this->view->type=$type;
		$currentPage = $this->_getParam('current_page') == 0? 1:$this->_getParam('current_page');
		$resultsPerPage = $this->_getParam('results_per_page') == 0? 12:$this->_getParam('results_per_page');
		$serValue = $this->_getParam('orderby') == ''? '':$this->_getParam('orderby');
		if($type == 1)
		{
		$ideaDetails = Doctrine::getTable('Tasks')->getPersonalTasks($memid,$currentPage,$resultsPerPage,$serValue);
		$this->view->getTasks = $ideaDetails;
		$jsonData['output'] = $this->view->render('index/task-view-list.html');
		}
		else if($type == 2)
		{
			$ideaDetails = Doctrine::getTable('Tasks')->getAssignToTasks($memid,$currentPage,$resultsPerPage,$serValue);
		$this->view->getTasks = $ideaDetails;
		$jsonData['output'] = $this->view->render('index/task-view-list.html');
		}
		else if($type == 3)
		{
			$ideaDetails = Doctrine::getTable('Tasks')->getAssignByTasks($memid,$currentPage,$resultsPerPage,$serValue);
		$this->view->getTasks = $ideaDetails;
		$jsonData['output'] = $this->view->render('index/task-view-list.html');
		}
		else
		{
				$ideaDetails= Doctrine::getTable('EmComments')->getTaskComments($type,$currentPage,$resultsPerPage);
				$this->view->getComments=$ideaDetails;
				//$this->view->taskDetails['task_id']=$id;
				$jsonData['output'] = $this->view->render('index/task-comments.html');
			
		}
		//echo '<pre>';print_r($ideaDetails);exit;
		$jsonData['pages'] = $ideaDetails['pages'];
	    $jsonData['pager'] = $ideaDetails['pager'];
	    $jsonData['currentPage'] = $ideaDetails['currentPage'];
		$jsonData['resultsCount'] = $ideaDetails['resultsCount'];
		$this->_helper->json->sendJson($jsonData);
		//echo '<pre>';print_r($ideaDetails);exit;
		
	
	}
	public function taskViewAction()
	{
		$type= $this->_getParam('id');
		$currentPage= base64_decode($this->_getParam('current_page'));
		$relation_id= base64_decode($this->_getParam('results_per_page'));
		
		//echo $currentPage;exit;
		
		$memid = $_SESSION["sess_userid"];
		$read_status= Doctrine::getTable('TaskRelations')->updateTaskReadStatus($memid,$relation_id,1);
			if($type==1)
			{
				$this->view->personalactive="active";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getPersonalTasks($memid,$currentPage,12);
				$r = Doctrine::getTable('TaskRelations')->getTaskRelationDetails($relation_id);
				$task_details = Doctrine::getTable('Tasks')->getPersonalTaskDetails($r['task_id'],$memid,$relation_id);
				$Assignees = Doctrine::getTable('TaskRelations')->getAssignees($r['task_id']);
				$comments= Doctrine::getTable('EmComments')->getTaskComments($r['task_id'],1,2);
				$this->view->getComments=$comments;
				//echo '<pre>';print_r($task_details);exit;
				
				//echo '<pre>';print_r($result);exit;
			}
			else if($type==2)
			{
				$this->view->personalactive="";
				$this->view->assigntoactive="active";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getAssignToTasks($memid,$currentPage,12);
				$r = Doctrine::getTable('TaskRelations')->getTaskRelationDetails($relation_id);
				$task_details = Doctrine::getTable('Tasks')->getAssignToTaskDetails($r['task_id'],$memid,$relation_id);
				$comments= Doctrine::getTable('EmComments')->getTaskComments($r['task_id'],1,2);
				$this->view->getComments=$comments;
				$Assignees = Doctrine::getTable('TaskRelations')->getAssignees($r['task_id']);
				//echo '<pre>';print_r($Assignees);exit;
				foreach($Assignees as $Assignees)
				{
					$photos[] = Doctrine::getTable('UserDetails')->getPhotos($Assignees['assigned_to']);
				}
				$this->view->assignees = $photos;
				//echo '<pre>';print_r($task_details);exit;
				//echo '<pre>';print_r($result);exit;
			}else{
				$this->view->personalactive="";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="active";
				$result = Doctrine::getTable('Tasks')->getAssignByTasks($memid,$currentPage,12);
				$r = Doctrine::getTable('TaskRelations')->getTaskRelationDetails($relation_id);
				$task_details = Doctrine::getTable('Tasks')->getAssignByTaskDetails($r['task_id'],$memid,$relation_id);
				$comments= Doctrine::getTable('EmComments')->getTaskComments($r['task_id'],1,2);
				$this->view->getComments=$comments;
				$Assignees = Doctrine::getTable('TaskRelations')->getAssignees($r['task_id']);
				//echo '<pre>';print_r($task_details);exit;
				foreach($Assignees as $Assignees)
				{
					$photos[] = Doctrine::getTable('UserDetails')->getPhotos($Assignees['assigned_to']);
				}
				$this->view->assignees = $photos;
				//echo '<pre>';print_r($photos);exit;
				//echo '<pre>';print_r($task_details);exit;
			}
			//	echo '<pre>';print_r($task_details);exit;
				
			$this->view->relationDetails = $r;
			$this->view->taskDetails = $task_details;
			$this->view->currentPage = $currentPage;			
			$this->view->params ='';
			$this->view->getTasks = $result;
			//echo $type;exit;
			$this->view->type= $type;
			$this->view->date_fromat = $this->CONFIG->date_format->date_time;
	}
	public function addDescriptionAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$memid=$_SESSION["sess_userid"];
	  	$task_id = $_POST['task_id'];
		$description = $_POST['description'];
		
		$result = Doctrine::getTable('Tasks')->addDescription($task_id,$description);
		$jsonData['output'] = 1;
		$this->_helper->json->sendJson($jsonData);	
	}
	public function getContactsAction()
	{
			$memid=$_SESSION["sess_userid"];
	$a = Doctrine::getTable('Contacts')->getContacts($memid);
				//echo '<pre>';print_r($a);exit;
				$jsonData = array();
				if(count($a)>0)
				{
					foreach($a as $key=>$mails)
					{
						$jsonData[$key]['key'] = $mails['contact_id'];
						$jsonData[$key]['value'] = $mails['first_name'];					
					}
				}
				$this->_helper->json->sendJson($jsonData);
	}
	public function createTaskAction()
	{
		$this->_helper->layout->disableLayout();
		$memid = $_SESSION["sess_userid"];
		$edit=$this->_getParam('edit');
		//echo $edit;exit;
		if($edit!="")
		{
			$task_id=$this->_getParam('task_id');
			$event_name=$this->_getParam('event_name');
			$task_details= Doctrine::getTable('Tasks')->getTaskDetails($task_id);
			//echo '<pre>';print_r($task_details);exit;
			$relation_details= Doctrine::getTable('TaskRelations')->getTaskRelationDetailsByTaskId($task_details['task_id']);
			//echo '<pre>';print_r($relation_details);exit;
			if($relation_details)
			{
			foreach($relation_details as $relation_details)
			{
				$assign_to[]=$relation_details['assigned_to'];
			}
			}
			else 
			{
				$assign_to=array();
			}
			if(count($assign_to)>0)
			{
				foreach($assign_to as $assign_to)
				{
					$user_details[]= Doctrine::getTable('Users')->getEmail($assign_to);
				}
			}
			else
			{
				$user_details=array();
			}
			$userZoneStartTime = GMTToUser($task_details['due_date'],3600);
			$task_details['due_date'] = date('Y-m-d',strtotime($userZoneStartTime));
			$task_details['due_time'] = date('h:i A',strtotime($userZoneStartTime));
			//	echo '<pre>';print_r($task_details);exit;
			
			$this->view->task_details=$task_details;
			$this->view->user_details=$user_details;
			$this->view->edit=$edit;
			$this->view->event_name=$event_name;
			$this->view->task_id=$task_id;
		}
		else
		{
		$this->view->task_details="";
		$this->view->edit="";
		}
		$events = Doctrine::getTable('EventsShared')->getEventsByUserId($memid);
		
		//echo '<pre>';print_r($result);exit;
		if($_POST)
		{
			
			include('../lib/mail/SendEmail.php');
			//echo '<pre>';print_r($_POST);exit;
					// connect to service##################################################################
				if($_POST['email']!="")
				{
					$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
					$user = $_POST['email'];
					$pass = $_POST['pwd'];
					$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
					// validate input
					$gcal = new Zend_Gdata_Calendar($client);
	
					$_POST['title'] = $_POST['taskname'];
					if (empty($_POST['title'])) {
					die('ERROR: Missing title');
					}

					$_POST['sdate_mm'] = '06';
					$_POST['sdate_dd'] = '08';
					$_POST['sdate_yy'] = '12';

					if (!checkdate($_POST['sdate_mm'], $_POST['sdate_dd'],
					$_POST['sdate_yy'])) {
					die('ERROR: Invalid start date/time');
					}

					$_POST['edate_mm'] = '11';
					$_POST['edate_dd'] = '06';
					$_POST['edate_yy'] = '12';

					if (!checkdate($_POST['edate_mm'], $_POST['edate_dd'],
					$_POST['edate_yy'])) {
					die('ERROR: Invalid end date/time');
					}

					$title = htmlentities($_POST['title']);
					$start = date(DATE_ATOM, mktime($_POST['sdate_hh'], $_POST['sdate_ii'],
					0, $_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy']));
					$end = date(DATE_ATOM, mktime($_POST['edate_hh'], $_POST['edate_ii'],
					0, $_POST['edate_mm'], $_POST['edate_dd'], $_POST['edate_yy']));

					// construct event object
					// save to server
					try {
					$event = $gcal->newEventEntry();
					$event->title = $gcal->newTitle($title);
					$when = $gcal->newWhen();
					$when->startTime = $start;
					$when->endTime = $end;
					$event->when = array($when);
					$gcal->insertEvent($event);
					} catch (Zend_Gdata_App_Exception $e) {
					echo "Error: " . $e->getResponse();
					}
					//echo 'Event successfully added!';
					//exit;
				}
			// end ################################################################################################3
			$startDate = trim($_POST['duedate']);
			$oldDate = trim($_POST['duedate']);
			$arr = explode('-', $oldDate);
			$startDate = $arr[2].'-'.$arr[0].'-'.$arr[1];
			//exit;

			
			$startTime = trim($_POST['duetime']);
			$startDateTime = $startDate.' '.$startTime;
			$startDateTime = changeToGMT($startDateTime,$_SESSION['TIMEZONEDIFF']);
			$_POST['duedate'] = $startDateTime;
			if($_POST['reccurance']==0)
			{
				$_POST['reccurance']="None";
			}
			else if($_POST['reccurance']==1)
			{
				$_POST['reccurance']="Weekly";
			}
			else
			{
				$_POST['reccurance']="Bi-Weekly";
			}
			//echo '<pre>';print_r($_POST);exit;
			if($_POST['event']==0 && isset($_POST['eventname'])!="")
			{
				//echo $_POST['eventname'];exit;
				$event_id= Doctrine::getTable('EventsShared')->addEvent($memid,$_POST['eventname']);
				$_POST['event']=$event_id;
			}
			//echo '<pre>';print_r($_POST);exit;
			$task_id= Doctrine::getTable('Tasks')->addTask($memid,$_POST);
				if($task_id)
				{
				$content_type="tasks";
				$share_type=1;
				$activity = Doctrine::getTable('EmActivities')->addActivity($task_id,$content_type,$memid,$share_type);
				}
			//echo isset($_POST['check_list']);exit;
			if(isset($_POST['select3'])!="")
			{
				//echo "shared";exit;
				$is_owner=0;
				$task_status="isprogress";
				foreach($_POST['select3'] as $receiver_id)
				{
				 //echo $receiver_id;exit;
				$result[]= Doctrine::getTable('TaskRelations')->addTaskRelations($memid,$receiver_id,$task_id,$is_owner,$task_status);
				$notifications = Doctrine::getTable('TasksNotifications')->getNotifications($r2['user_id']);
				if($notifications)
				{
					if(isset($notifications[0]['assigned_task'])!="off")
					{
						$email= Doctrine::getTable('Users')->getEmail($receiver_id);
						$loginLink = $this->CONFIG->serverAddress.'home';
						$Subject = "Task Notification from EmotionsMirror";
						$Message = 'Hello "'.$email['first_name'].'",<br/><br/>you got a task in your emotionmirror  <br/><br/>
							<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
								Emirror team';
						global $serverAddress;
						//sendMail($email['email'],$Subject,$Message,$_SESSION["sess_email"]);
					}
				}
				}
				//echo '<pre>';print_r($result);exit;
			}
			else
			{
				$is_owner=1;
				$receiver_id=$memid;
				$task_status="accepted";
				$result= Doctrine::getTable('TaskRelations')->addTaskRelations($memid,$receiver_id,$task_id,$is_owner,$task_status);
			}
			$this->_redirect("tasks/index/task-list/1");
		}
		$this->view->events= $events;
		$this->view->eventCount= count($events);
	}
	public function updateTaskAction()
	{
		$task_id=$this->_getParam('id');
		$memid = $_SESSION["sess_userid"];
		$startDate = trim($_POST['duedate']);
			$oldDate = trim($_POST['duedate']);
			$arr = explode('-', $oldDate);
			$startDate = $arr[2].'-'.$arr[0].'-'.$arr[1];
			//exit;

			
			$startTime = trim($_POST['duetime']);
			$startDateTime = $startDate.' '.$startTime;
			$startDateTime = changeToGMT($startDateTime,$_SESSION['TIMEZONEDIFF']);
			$_POST['duedate'] = $startDateTime;
			if($_POST['reccurance']==0)
			{
				$_POST['reccurance']="None";
			}
			else if($_POST['reccurance']==1)
			{
				$_POST['reccurance']="Weekly";
			}
			else
			{
				$_POST['reccurance']="Bi-Weekly";
			}
		//echo '<pre>';print_r($_POST);exit;
		$result= Doctrine::getTable('Tasks')->updateTaskDetails($task_id,$_POST,$memid);
		$user_ids="";
		if(isset($_POST['select3'])!="")
		{
			foreach($_POST['select3'] as $user_id)
			{
				$user_ids.=$user_id.",";
			}
			
			$user_ids = trim($user_ids,',');
			//echo '<pre>';print_r($user_ids);exit;
			$result= Doctrine::getTable('TaskRelations')->deleteTaskRelationsDetails($task_id,$user_ids);
		}
		if(isset($_POST['select3'])!="")
			{
				//echo "shared";exit;
				$is_owner=0;
				$task_status="isprogress";
				foreach($_POST['select3'] as $receiver_id)
				{
				 //echo $receiver_id;exit;
				 $isrecord= Doctrine::getTable('TaskRelations')->checkTaskRelations($receiver_id,$task_id);
				 //echo '<pre>';print_r($isrecord);exit;
				 if(count($isrecord)==0)
				 {
					$result[]= Doctrine::getTable('TaskRelations')->addTaskRelations($memid,$receiver_id,$task_id,$is_owner,$task_status);
					$notifications = Doctrine::getTable('TasksNotifications')->getNotifications($r2['user_id']);
					if($notifications)
					{
						if(isset($notifications[0]['assigned_task'])!="off")
						{
							$email= Doctrine::getTable('Users')->getEmail($receiver_id);
							$loginLink = $this->CONFIG->serverAddress.'home';
							$Subject = "Task Notification from EmotionsMirror";
							$Message = 'Hello "'.$email['first_name'].'",<br/><br/>you got a task in your emotionmirror  <br/><br/>
								<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
									Emirror team';
							global $serverAddress;
							//sendMail($email['email'],$Subject,$Message,$_SESSION["sess_email"]);
						}
					}
				 }
				}
				//echo '<pre>';print_r($result);exit;
			}
			else
			{
				$is_owner=1;
				$receiver_id=$memid;
				$task_status="accepted";
				$isrecord= Doctrine::getTable('TaskRelations')->checkTaskRelations($receiver_id,$task_id);
				if(count($isrecord==0))
				{
					$result= Doctrine::getTable('TaskRelations')->addTaskRelations($memid,$receiver_id,$task_id,$is_owner,$task_status);
				}
			}
			$this->_redirect("tasks/index/task-list/1");
		
	}
	public function assignTaskAction()
	{
		$task_id=$this->_getParam('task_id');
		//echo $task_id;exit;
		$event_id=$this->_getParam('event_id');
		//echo $task_id;exit;
		$this->_helper->layout->disableLayout();
		$memid = $_SESSION["sess_userid"];
		$result= Doctrine::getTable('Contacts')->getContacts($memid);
		$this->view->contacts=$result;
		$this->view->task_id=$task_id;
		$this->view->event_id=$event_id;
		if($_POST)
		{
			$task_id=$this->_getParam('id');
		//echo $task_id;exit;
			$event_id=$this->_getParam('current_page');
			//echo $task_id.'and'.$event_id;exit;
			include('../lib/mail/SendEmail.php');
			//echo '<pre>';print_r($_POST);exit;
			$email= Doctrine::getTable('TaskRelations')->deleteTaskRelation($task_id);
				//$event_id= Doctrine::getTable('Tasks')->getTaskDetails($task_id);
				$_POST['event']=$event_id;
			if(isset($_POST['check_list'])!="")
			{
				//echo "shared";exit;
				$is_owner=0;
				$task_status="isprogress";
				foreach($_POST['check_list'] as $receiver_id)
				{
				$result[]= Doctrine::getTable('TaskRelations')->addTaskRelations($memid,$receiver_id,$task_id,$is_owner,$task_status);
				//$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($r2['user_id']);
				//if(isset($notifications['uploadphoto_their'])!="off")
				$email= Doctrine::getTable('Users')->getEmail($receiver_id);
					$loginLink = $this->CONFIG->serverAddress.'home';
					$Subject = "Task Notification from EmotionsMirror";
					$Message = 'Hello "'.$email['first_name'].'",<br/><br/>you got a task in your emotionmirror  <br/><br/>
						<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
							Emirror team';
					global $serverAddress;
					//sendMail($email['email'],$Subject,$Message,$_SESSION["sess_email"]);
				}
				//echo '<pre>';print_r($result);exit;
			}
			$this->_redirect("tasks/index/task-list/1");
		}
	}
	public function favoriteAction()
	{
		//echo '<pre>';print_r($_POST);exit;
	  	$memid = $_SESSION["sess_userid"];
		$task_id=$_POST["task_id"];
		$status=$_POST["status"];
		$type=$_POST["type"];
		if($status=="Active")
		{
		 //trig $status;exit;
		$result= Doctrine::getTable('MyFavorites')->addToFavorite($memid,$task_id,$type);
		//echo '<pre>';print_r($result);exit;
		}
		else
		{
			if($status=="Inactive")
			{
				//echo "inactive";exit;
				$result= Doctrine::getTable('MyFavorites')->inactiveFavorite($memid,$task_id,$type);
				//echo '<pre>';print_r($result);exit;
			}
		}
		$jsonData['output'] = $result;
		$this->_helper->json->sendJson($jsonData);
			
	}
	public function deleteTasksAction()
	{
		include('../lib/mail/SendEmail.php');
		//echo '<pre>';print_r($_POST);exit;
	  	$memid = $_SESSION["sess_userid"];
		$id = $_POST["val"];
		$action = $_POST["action"];
		//echo $id."  and  ".$action;exit;
		if($action == "task_id")
		{
		$result= Doctrine::getTable('TaskRelations')->deleteTasksByTaskId($id);
		$assign_by= Doctrine::getTable('Tasks')->getAssignByPerson($id);
			//echo '<pre>';print_r($assign_by);exit;
			$user_details=Doctrine::getTable('Users')->getEmail($assign_by['added_by']);
		}
		else
		{		
			if($action == "relation_id")
			{
			$result= Doctrine::getTable('TaskRelations')->deleteTasksByRelationId($id);
			$task_details = Doctrine::getTable('TaskRelations')->getTaskRelationDetails($id);
			//echo '<pre>';print_r($task_details);exit;
			$user_details=Doctrine::getTable('Users')->getEmail($task_details['assigned_by']);
			//echo $result;exit;
			}
		}
		$notifications = Doctrine::getTable('TasksNotifications')->getNotifications($user_details['user_id']);
			//echo '<pre>';print_r($notifications);exit;
			if($notifications)
			{
					if($notifications[0]['task_deleted']!="off")
					{
						$loginLink = $this->CONFIG->serverAddress.'home';
						$Subject = "Task delete Notification from EmotionsMirror";
						$Message = 'Hello "'.$user_details['first_name'].'",<br/><br/>your assigned task was deleted in your emotionmirror  <br/><br/>
							<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
								Emirror team';
						global $serverAddress;
						//sendMail($user_details['email'],$Subject,$Message,$_SESSION["sess_email"]);
					}
			}
		//echo '<pre>';print_r($result);exit;
		$type=$_POST['type'];
		$current_page=$_POST['current_page'];
		if($type==1)
			{
				$this->view->personalactive="active";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getPersonalTasks($memid,$current_page,12);
				//echo '<pre>';print_r($result);exit;
			}
			else if($type==2)
			{
				$this->view->personalactive="";
				$this->view->assigntoactive="active";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getAssignToTasks($memid,$current_page,12);
				//echo '<pre>';print_r($result);exit;
			}else{
				$this->view->personalactive="";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="active";
				$result = Doctrine::getTable('Tasks')->getAssignByTasks($memid,$current_page,12);
			}
			//echo '<pre>';print_r($result);exit;
			$this->view->params ='';
			$this->view->getTasks = $result;
			$this->view->type= $type;
		$jsonData['output'] = $this->view->render('index/task-view-list.html');
		$this->_helper->json->sendJson($jsonData);
			
	}
	public function submitCommentAction()
	{	
		include('../lib/mail/SendEmail.php');
		//echo '<pre>';print_r($_POST);exit;
		$memid = $_SESSION["sess_userid"];
			$result= Doctrine::getTable('EmComments')->addComments($memid,$_POST);
			$comments= Doctrine::getTable('EmComments')->getTaskComments($_POST['album_id'],1,12);
			$this->view->getComments=$comments;
			//echo '<pre>';print_r($comments);exit;
			//$this->view->photo_id=$_POST['photo_id'];
			$assign_by= Doctrine::getTable('Tasks')->getAssignByPerson($_POST['album_id']);
			//echo '<pre>';print_r($assign_by);exit;
			$user_details=Doctrine::getTable('Users')->getEmail($assign_by['added_by']);
			
			$notifications = Doctrine::getTable('TasksNotifications')->getNotifications($user_details['user_id']);
			//echo '<pre>';print_r($notifications);exit;
			if($notifications)
			{
					if($notifications[0]['comments_on_tasks']!="off")
					{
						$loginLink = $this->CONFIG->serverAddress.'home';
						$Subject = "Comment Notification from EmotionsMirror";
						$Message = 'Hello "'.$user_details['first_name'].'",<br/><br/>you got a Comment on your task in your emotionmirror  <br/><br/>
							<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
								Emirror team';
						global $serverAddress;
						//sendMail($user_details['email'],$Subject,$Message,$_SESSION["sess_email"]);
					}
			}
			$jsonData['output'] = 1;
			$this->_helper->json->sendJson($jsonData);
	}
	public function changeStatusAction()
	{
		include('../lib/mail/SendEmail.php');
		//echo '<pre>';print_r($_POST);exit;
		$id = $_POST['val'];
		$relation_id = $_POST['userId'];
		$task_details = Doctrine::getTable('TaskRelations')->getTaskRelationDetails($relation_id);
		//echo '<pre>';print_r($task_details);exit;
		$user_details=Doctrine::getTable('Users')->getEmail($task_details['assigned_by']);
		$notifications = Doctrine::getTable('TasksNotifications')->getNotifications($user_details['user_id']);
		///echo '<pre>';print_r($notifications);exit;
		if($id==1)
		{
			$task_status="completed";
			if($notifications)
			{
			if($notifications[0]['task_completed']!="off")
					{
						$loginLink = $this->CONFIG->serverAddress.'home';
						$Subject = "task status Notification from EmotionsMirror";
						$Message = 'Hello "'.$user_details['first_name'].'",<br/><br/>youy task status changed in your emotionmirror  <br/><br/>
							<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
								Emirror team';
						global $serverAddress;
						//sendMail($user_details['email'],$Subject,$Message,$_SESSION["sess_email"]);
					}
			}
		}
		else if($id==2)
		{
			$task_status="accepted";
			if($notifications)
			{
			if($notifications[0]['task_accepted']!="off")
					{
					$loginLink = $this->CONFIG->serverAddress.'home';
						$Subject = "task status Notification from EmotionsMirror";
						$Message = 'Hello "'.$user_details['first_name'].'",<br/><br/>youy task status changed in your emotionmirror  <br/><br/>
							<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
								Emirror team';
						global $serverAddress;
						//sendMail($user_details['email'],$Subject,$Message,$_SESSION["sess_email"]);
					}
				}
		}
		else
		{
			$task_status="Rejected";
			if($notifications)
			{
			if($notifications[0]['task_rejected']!="off")
					{
						$loginLink = $this->CONFIG->serverAddress.'home';
						$Subject = "task status Notification from EmotionsMirror";
						$Message = 'Hello "'.$user_details['first_name'].'",<br/><br/>youy task status changed in your emotionmirror  <br/><br/>
							<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
								Emirror team';
						global $serverAddress;
						//sendMail($user_details['email'],$Subject,$Message,$_SESSION["sess_email"]);
					}
			}
		}
		$result = Doctrine::getTable('TaskRelations')->updateTaskStatus($relation_id,$task_status);
		$task_details = Doctrine::getTable('TaskRelations')->getTaskRelationDetails($relation_id);
		//echo '<pre>';print_r($task_details);exit;
		$user_details=Doctrine::getTable('Users')->getEmail($task_details['assigned_by']);
		$jsonData['output'] = $task_status;
		$this->_helper->json->sendJson($jsonData);
	
	}
	public function changePriorityStatusAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		
		//echo $current_page;exit;
	  	$memid = $_SESSION["sess_userid"];
		$realtion_id=$_POST["realtion_id"];
		$status=$_POST["status"];
		$module_type=$_POST["module_type"];
		$results= Doctrine::getTable('TaskRelations')->changePriorityStatus($memid,$realtion_id,$status);
		$type=$_POST['type'];
		//echo $type;exit;
		$current_page=$_POST['current_page'];
		
		if($type==1)
			{
				$this->view->personalactive="active";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getPersonalTasks($memid,$current_page,12);
				//echo '<pre>';print_r($result);exit;
			}
			else if($type==2)
			{
				$this->view->personalactive="";
				$this->view->assigntoactive="active";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getAssignToTasks($memid,$current_page,12);
				//echo '<pre>';print_r($result);exit;
			}else{
				$this->view->personalactive="";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="active";
				$result = Doctrine::getTable('Tasks')->getAssignByTasks($memid,$current_page,12);
			}
			//echo '<pre>';print_r($result);exit;
			$this->view->params ='';
			$this->view->getTasks = $result;
			$this->view->type= $type;
		$jsonData['output'] = $this->view->render('index/task-view-list.html');
		$this->_helper->json->sendJson($jsonData);
			
	}
	public function favoritesAction()
	{
		//echo '<pre>';print_r($_POST);exit;
	  	$memid = $_SESSION["sess_userid"];
		$task_id=$_POST["task_id"];
		$status=$_POST["status"];
		$module_type=$_POST["module_type"];
		if($status=="Active")
		{
		 //echo $status;exit;
		$result= Doctrine::getTable('MyFavorites')->addToFavorite($memid,$task_id,$module_type);
		//echo '<pre>';print_r($result);exit;
		}
		else
		{
			if($status=="Inactive")
			{
				//echo "inactive";exit;
				$result= Doctrine::getTable('MyFavorites')->inactiveFavorite($memid,$task_id,$module_type);
				//echo '<pre>';print_r($result);exit;
			}
		}
		$type=$_POST['type'];
		$current_page=$_POST['current_page'];
		if($type==1)
			{
				$this->view->personalactive="active";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getPersonalTasks($memid,$current_page,12);
				//echo '<pre>';print_r($result);exit;
			}
			else if($type==2)
			{
				$this->view->personalactive="";
				$this->view->assigntoactive="active";
				$this->view->assignbyactive="";
				$result = Doctrine::getTable('Tasks')->getAssignToTasks($memid,$current_page,12);
				//echo '<pre>';print_r($result);exit;
			}else{
				$this->view->personalactive="";
				$this->view->assigntoactive="";
				$this->view->assignbyactive="active";
				$result = Doctrine::getTable('Tasks')->getAssignByTasks($memid,$current_page,12);
			}
			//echo '<pre>';print_r($result);exit;
			$this->view->params ='';
			$this->view->getTasks = $result;
			$this->view->type= $type;
		$jsonData['output'] = $this->view->render('index/task-view-list.html');
		$this->_helper->json->sendJson($jsonData);
			
	}

}	
	